<?php
include_once '../connexpdo.php';
function utf8_array($data) {
	return utf8_encode ( $data );
}

if (! isset ( $_POST ['DateDebut'] )) {
	$query = "SELECT idproblematique, COUNT(idAppels)as numpb, p.nature   FROM appels AS a INNER JOIN problematique AS p ON a.idproblematique = p.id WHERE p.categPrinc != 0 GROUP BY idproblematique";
	
	$return = $connexion->query ( $query );
	$vretour = array ();
	while ( $row = $return->fetch () ) {
		// $data[]=array_map('utf8_array', array("nature"=>$row['nature']));
		$data [] = array (
				"id" => $row ['idproblematique'],
				"num" => $row ['numpb'],
				"nature" => utf8_array ( $row ['nature'] ) 
		);
		array_push ( $vretour, $data );
	}
	echo json_encode ( $data );
} else {
	$query = 'SELECT idproblematique, COUNT(idAppels)as numpb, p.nature   FROM appels AS a INNER JOIN problematique AS p ON a.idproblematique = p.id WHERE p.categPrinc != 0 AND dateDebut BETWEEN \'' . $_POST ['DateDebut'] . '\' AND \'' . $_POST ['DateFin'] . '\' GROUP BY idproblematique;';
	$return = $connexion->query ( $query );
	$vretour = array ();
	while ( $row = $return->fetch () ) {
		// $data[]=array_map('utf8_array', array("nature"=>$row['nature']));
		$data [] = array (
				"idd" => $row ['idproblematique'],
				"num" => $row ['numpb'],
				"nature" => utf8_array ( $row ['nature'] ) 
		);
		array_push ( $vretour, $data );
	}
	echo json_encode ( $data );
}
?>